home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XA_6S.ZIP / SOURCE / SCRLOBJC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-11  |  5.0 KB  |  250 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <stdlib.h>
  9. #include <osbind.h>
  10. #include <mintbind.h>
  11. #ifdef LATTICE
  12. #undef abs        /* MiNTlib (PL46) #define is buggy! */
  13. #define abs(i)    __builtin_abs(i)
  14. #endif
  15. #include "XA_DEFS.H"
  16. #include "XA_TYPES.H"
  17. #include "XA_GLOBL.H"
  18. #include "K_DEFS.H"
  19. #include "RECTLIST.H"
  20. #include "BOX3D.H"
  21. #include "objects.h"
  22. #include "FRM_ALRT.H"
  23.  
  24. /*
  25.     Setup a scrolling list structure for an object
  26.     - I've provided this as I don't expect any resource editor to support
  27.     XaAES' extentions to the object types....
  28. */
  29.  
  30. short set_scroll(OBJECT *form, short objc, char *title)
  31. {
  32.     OBJECT *ob=form+objc;
  33.     SCROLL_INFO *sinfo;
  34.     
  35.     sinfo=(SCROLL_INFO*)malloc(sizeof(SCROLL_INFO));
  36.  
  37.     if (!sinfo)
  38.         return FALSE;
  39.     
  40.     sinfo->scrl_current=NULL;
  41.     sinfo->scrl_dstart=NULL;
  42.     sinfo->scrl_start=NULL;
  43.     sinfo->scrl_title=title;
  44.     sinfo->scrl_count=0;
  45.     sinfo->scrl_colour.borderc=BLACK;
  46.     sinfo->scrl_colour.textc=BLACK;
  47.     sinfo->scrl_colour.opaque=0;
  48.     sinfo->scrl_colour.pattern=IP_HOLLOW;
  49.     sinfo->scrl_colour.fillc=WHITE;
  50.     sinfo->scrl_status=0;
  51.     sinfo->scrl_f_click=NULL;
  52.     sinfo->scrl_f_dclick=NULL;
  53.     
  54.     ob->ob_spec=(void*)sinfo;
  55.     ob->ob_type=G_SLIST;
  56.     
  57.     return TRUE;
  58. }
  59.  
  60. short add_scroll_entry(OBJECT *form, short objc, SCROLL_ENTRY *entry)
  61. {
  62.     SCROLL_INFO *list;
  63.     SCROLL_ENTRY *last,*new_entry;
  64.     OBJECT *ob=form+objc;
  65.     
  66.     list=(SCROLL_INFO*)ob->ob_spec;
  67.     new_entry=(SCROLL_ENTRY*)malloc(sizeof(SCROLL_ENTRY));
  68.     
  69.     if (!new_entry)
  70.     {
  71.         return FALSE;
  72.     }
  73.     
  74.     new_entry->next=NULL;
  75.     last=list->scrl_start;
  76.     if (last)
  77.     {
  78.         while(last->next)
  79.             last=last->next;
  80.         last->next=new_entry;
  81.         new_entry->prev=last;
  82.     }else{
  83.         new_entry->prev=NULL;
  84.         list->scrl_start=list->scrl_current=list->scrl_dstart=new_entry;
  85.     }
  86.     new_entry->text=entry->text;
  87.     new_entry->icon=entry->icon;
  88.     if (entry->icon)
  89.     {
  90.         new_entry->icon->ob_x=0;
  91.         new_entry->icon->ob_y=0;
  92.         new_entry->icon->ob_flags|=HIDETREE;
  93.     }
  94.     
  95.     return TRUE;
  96. }
  97.  
  98. void empty_scroll_list(OBJECT *form, short objc)
  99. {
  100.     SCROLL_INFO *list;
  101.     SCROLL_ENTRY *this,*next;
  102.     OBJECT *ob=form+objc;
  103.  
  104.     list=(SCROLL_INFO*)ob->ob_spec;
  105.     this=next=list->scrl_start;
  106.     
  107.     while(this)
  108.     {
  109.         next=this->next;
  110.         free(this);
  111.         this=next;
  112.     }
  113.     
  114.     list->scrl_start=list->scrl_current=list->scrl_dstart=NULL;
  115. }
  116.  
  117. void click_scroll_list(OBJECT *form, short objc, short cx, short cy)
  118. {
  119.     SCROLL_INFO *list;
  120.     SCROLL_ENTRY *this;
  121.     OBJECT *ob=form+objc;
  122.     short mx,my,mb,y;    
  123.  
  124.     list=(SCROLL_INFO*)ob->ob_spec;
  125.     
  126.     object_abs_coords(form, objc, &mx, &my);
  127.  
  128.     cx-=mx;    /* Get click position relative to the scroller */
  129.     cy-=my;
  130.  
  131.     if (cy<display.c_max_h)
  132.         return;
  133.  
  134.     if (cx>ob->ob_width - display.c_max_w - 4)
  135.     {
  136.         DIAGS(("click_scroll: cy=%x\n",cy));
  137.         
  138.         if ((cy>display.c_max_h+1)&&(cy<display.c_max_h*2+4))
  139.         {
  140.             list->scrl_status=SCRLSTAT_UP;
  141.         }else{
  142.             if(cy>ob->ob_height-display.c_max_h-1)
  143.             {
  144.                 list->scrl_status=SCRLSTAT_DOWN;
  145.             }
  146.         }            
  147.  
  148.         vq_mouse(V_handle, &mb, &mx, &my);
  149.         
  150.         do{
  151.  
  152.             if ((list->scrl_status==SCRLSTAT_UP)&&(list->scrl_dstart!=list->scrl_start))
  153.             {
  154.                 list->scrl_dstart=list->scrl_dstart->prev;
  155.                 v_hide_c(V_handle);
  156.                 draw_object_tree(form, objc, 1);
  157.                 v_show_c(V_handle, 1);
  158.             }
  159.  
  160.             if ((list->scrl_status==SCRLSTAT_DOWN)&&(list->scrl_dstart->next))
  161.             {
  162.                 list->scrl_dstart=list->scrl_dstart->next;
  163.                 v_hide_c(V_handle);
  164.                 draw_object_tree(form, objc, 1);
  165.                 v_show_c(V_handle, 1);
  166.             }
  167.         
  168.             Fselect(20,NULL,NULL,NULL);    /* Wait a while to slow the scrolling down */
  169.  
  170.             vq_mouse(V_handle, &mb, &mx, &my);
  171.         }while(mb);
  172.     
  173.         list->scrl_status=SCRLSTAT_RDB;
  174.  
  175.     }else{
  176.         
  177.         y=5+2*display.c_max_h; this=list->scrl_dstart;
  178.         while((this)&&(y<cy))
  179.         {
  180.                 this=this->next;
  181.                 y+=display.c_max_h;
  182.         }
  183.  
  184.         if (this)
  185.         {
  186.             list->scrl_current=this;
  187.             list->scrl_status=0;
  188.             
  189.             if (list->scrl_f_click)            /* Call the new object selected callback */
  190.                 (*(list->scrl_f_click))(form,objc);
  191.             
  192.         }else{
  193.             list->scrl_status=SCRLSTAT_RDB;
  194.         }
  195.         
  196.     }
  197.     
  198.     v_hide_c(V_handle);
  199.     draw_object_tree(form, objc, 1);
  200.     v_show_c(V_handle, 1);
  201.     list->scrl_status=0;
  202.     
  203. }
  204.  
  205. void dclick_scroll_list(OBJECT *form, short objc, short cx, short cy)
  206. {
  207.     SCROLL_INFO *list;
  208.     SCROLL_ENTRY *this;
  209.     OBJECT *ob=form+objc;
  210.     short mx,my,mb,y;    
  211.  
  212.     list=(SCROLL_INFO*)ob->ob_spec;
  213.     
  214.     object_abs_coords(form, objc, &mx, &my);
  215.  
  216.     cx-=mx;    /* Get click position relative to the scroller */
  217.     cy-=my;
  218.  
  219.     if (cy<display.c_max_h)
  220.         return;
  221.  
  222.     if (cx>ob->ob_width - display.c_max_w - 4)
  223.         return;
  224.  
  225.     y=5+2*display.c_max_h; this=list->scrl_dstart;
  226.     while((this)&&(y<cy))
  227.     {
  228.             this=this->next;
  229.             y+=display.c_max_h;
  230.     }
  231.  
  232.     if (this)
  233.     {
  234.         list->scrl_current=this;
  235.         list->scrl_status=0;
  236.     }else{
  237.         list->scrl_status=SCRLSTAT_RDB;
  238.     }
  239.     
  240.     v_hide_c(V_handle);
  241.     draw_object_tree(form, objc, 1);
  242.     v_show_c(V_handle, 1);
  243.     list->scrl_status=0;
  244.     
  245.     if (list->scrl_f_dclick)
  246.         (*(list->scrl_f_dclick))(form,objc);
  247.     
  248. }
  249.  
  250.